package com.eascs.web.p2p.action;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.app.dao.PageResult;
import com.eascs.common.util.UrlUtil;
import com.eascs.p2p.common.service.InvestorService;
import com.eascs.p2p.common.vo.InvestorVO;
import com.eascs.p2p.common.vo.ModelResult;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.view.BaseRestResult;
import com.eascs.site.view.ViewContext;
import com.eascs.site.view.button.AjaxButton;
import com.eascs.site.view.button.Button;
import com.eascs.site.view.button.ShowButtonFilter;
import com.eascs.tag.MenuTag;
import com.eascs.web.p2p.common.BaseMasterViewController;

@Controller
@RequestMapping("/investor")
public class InvestorController extends BaseMasterViewController {

	@Reference
	InvestorService  investorService;

	@Override
	public void preHandle() {
		super.preHandle();
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "ManageInvestor");
	}
	
	@RequestMapping(value = "/index")
	public String index(InvestorVO vo) {

		vo.setPageSize(10);
		ModelResult<PageResult<Object[]>> model = investorService.findPageInvestorEntity(vo);
		PageResult<Object[]> pageResult=new PageResult<Object[]>();
		if(model.isSuccess()){
			 pageResult = model.getModel();
		} 
			
		

		String[] titles = { "姓名", "手机号码", "身份证号码","银行卡号","注册来源", "注册时间", "最后登录","账户总资产" ,  "账户余额", "投资金额", "获得收益","状态"};
		
		AjaxButton openButton=new AjaxButton("启用                   ", "/investorRest/updateStatus?status=0&id=");
		openButton.setShowButtonFilter(new ShowButtonFilter(){

			@Override
			public boolean filter(Object param) {
				Object[] params=(Object[]) param;
				return "停用".equals(params[12]);
			}
			
		});
		
		AjaxButton closeButton=new AjaxButton("禁用                   ", "/investorRest/updateStatus?status=1&id=");
		closeButton.setShowButtonFilter(new ShowButtonFilter(){

			@Override
			public boolean filter(Object param) {
				Object[] params=(Object[]) param;
				return "启用".equals(params[12]);
			}
			
		});
		Button[] detailButton = new Button[] {openButton,closeButton};
		String pageUrl = "/investor/index";
		pageUrl = UrlUtil.appendUrl(pageUrl, "keywords", vo.getKeywords());
		pageUrl = UrlUtil.appendUrl(pageUrl, "beginCreateTime",vo.getBeginCreateTime());
		pageUrl = UrlUtil.appendUrl(pageUrl, "endCreateTime", vo.getEndCreateTime());
		if (vo.getChannel() > 0) {
			pageUrl = UrlUtil.appendUrl(pageUrl, "channel", String.valueOf(vo.getChannel()));
		}

		pageUrl = UrlUtil.appendUrl(pageUrl, "status", vo.getStatus());

		pageUrl = UrlUtil.appendUrl(pageUrl, "showPage", "");
	
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, pageUrl );
		paginationInfo.setBuildPagingNavigation(true);
		// paginationInfo.setFirstRenderColumnIndex(1);
		paginationInfo.setMoreButtons(detailButton);
		ViewContext.put("paginationInfo", paginationInfo);
		ViewContext.put("vo", vo);
		
		BaseRestResult.refresh();
		return "/investor/index";
	}

	
}
